//
//  YZMTradeBasicViewController.m
//  YZMicroStock
//
//  Created by wangminhong on 16/5/31.
//  Copyright © 2016年 cqjr. All rights reserved.
//

#import "YZMTradeBasicViewController.h"
#import "YZMTradeFilterView.h"

@interface YZMTradeBasicViewController ()

@property (nonatomic, strong) YZMTradeFilterView *filterView;


@end

@implementation YZMTradeBasicViewController

//- (void)viewWillAppear:(BOOL)animated {
//
//    [super viewWillAppear:YES];
////    self.navigationItem.titleView = self.navTitleView;
//
//    self.navigationItem.titleView = self.segment;
//
//}
//
//- (void)viewWillDisappear:(BOOL)animated {
//
//    [super viewWillDisappear: YES];
//    self.navigationItem.titleView = nil;
//}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [YZMAppStyle appBackgroundColor];
    
//    self.navTitleView = [[YZMNavigationTitleView alloc] initWithFrame:CGRectMake(0, 0, 64, 32)];
//    [self.navTitleView setTitle: self.viewName];
//    [self.navTitleView addTarget: self action: @selector(titleBarPressed:) forControlEvents: UIControlEventTouchUpInside];
}

- (void)segmentPressed: (UISegmentedControl *)seg {
    
    NSLog(@"%zd",seg.selectedSegmentIndex);
    switch (seg.selectedSegmentIndex) {
        case 0:
            [self showTradeViewWithType:YZM_TRADE_TYPE_FOR_A_STOCK];
            break;
        case 1:
            [self showTradeViewWithType:YZM_TRADE_TYPE_FOR_A_STOCK_D];
            break;
        default:
            break;
    }
}

- (void)titleBarPressed: (id)sender
{
    if (self.navTitleView.showFlag) {
        [self.navTitleView arrowDown];
        [self.filterView hide];
    }
    else
    {
        [self.navTitleView arrowUp];
        if (!self.filterView) {
            
            __weak __typeof(&*self) weakSelf = self;
            self.filterView = [YZMTradeFilterView new];
            self.filterView.filterHandler = ^(YZM_TRADE_TYPE type){
                
                [weakSelf showTradeViewWithType:type];
            };
            self.filterView.hideHandler = ^{
              
                [weakSelf.navTitleView arrowDown];
            };
            [self.view addSubview:self.filterView];
            [self.filterView mas_makeConstraints:^(MASConstraintMaker *make) {
                
                make.edges.equalTo(self.view);
            }];
            [self.filterView loadButtonsForTypes:self.otherTypeList];
            
        }else{
            
            [self.filterView show];
        }
    }
}

- (void)showTradeViewWithType:(YZM_TRADE_TYPE)type{
    
    switch (type) {
        case YZM_TRADE_TYPE_FOR_A_STOCK:
            break;
            
        case YZM_TRADE_TYPE_FOR_A_STOCK_D:
            break;
            
        case YZM_TRADE_TYPE_FOR_A_STOCK_ONE:
        case YZM_TRADE_TYPE_FOR_A_STOCK_SIM:
            break;
        case YZM_TRADE_TYPE_FOR_A_STOCK_FREE:
            break;
        case YZM_TRADE_TYPE_FOR_A_STOCK_YLB:
            break;
    }
}

- (void)setTradeType:(YZM_TRADE_TYPE)tradeType{
    
    _tradeType = tradeType;
    self.otherTypeList = [@[@[[sYZMTradeNameForAStock stringByAppendingString:@" 点买A股"],@(YZM_TRADE_TYPE_FOR_A_STOCK)],
                            @[[sYZMTradeNameForAStockD stringByAppendingString:@" 点买A股"],@(YZM_TRADE_TYPE_FOR_A_STOCK_D)]] mutableCopy];
    switch (tradeType) {
        case YZM_TRADE_TYPE_FOR_A_STOCK: {
            self.viewName = [sYZMTradeNameForAStock stringByAppendingString:@" 点买A股"];
            [self.otherTypeList removeObjectAtIndex:0];
            break;
        }
        case YZM_TRADE_TYPE_FOR_A_STOCK_D: {
            self.viewName = [sYZMTradeNameForAStockD stringByAppendingString:@" 点买A股"];
            [self.otherTypeList removeObjectAtIndex:1];
            break;
        }
        case YZM_TRADE_TYPE_FOR_A_STOCK_ONE:
        case YZM_TRADE_TYPE_FOR_A_STOCK_SIM:
        case YZM_TRADE_TYPE_FOR_A_STOCK_FREE:
            break;
    }
}

- (void)startTimer{
    
}

- (void)stopTimer{
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
